package com.nami.logic.rocketmq.consumer.config;

import org.apache.rocketmq.client.producer.MessageQueueSelector;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageQueue;

import java.util.List;

public class HashMessageQueueSelector implements MessageQueueSelector {

    @Override
    public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) {
        String key = (String) arg;
        int hashCode = key.hashCode();
        int index = Math.abs(hashCode) % mqs.size();
        return mqs.get(index);
    }

}
